<? 
class NToolBar extends NObject{
	var $_active=false;
	var $_items=array(); //array of stdClass (href,title)
	static  $tplsmap=array();
	function __construct(){
	}
	function &getInstance($type='cabinet'){
		static $instances=array();
		
		if (!array_key_exists($type, $instances)) {
			//require_once dirname(__FILE__)."/class/toolbar.php";
			$c=__CLASS__;
			$instances[$type]=& new $c();
			$_tpl=array_key_exists($type,self::$tplsmap)?self::$tplsmap[$type]:'default';
			$_tpl=$_tpl.'.phtml';
		
			$instances[$type]->_tpl=$_tpl;
		}
		return $instances[$type];
		
	}
	
	function render(){
		if (!$this->active) return "";
ob_start();
include(dirname(__FILE__)."/tpls/".$this->_tpl);
$_return=ob_get_contents();
ob_end_clean();
return $_return;
	}

function display(){
	echo $this->render();
}
function &addItem($oItem){
	
	if (is_array($oItem)) $oItem=(object) $oItem;
	if (!$oItem->type)$oItem->type='a';	
	array_push($this->_items,$oItem);
	if (!$this->get('active')) $this->set('active',true);
	//return $this;
	
}
function &addCaption($texthtml){
	$oItem->type="caption";
	$oItem->text=$texthtml;
	$this->addItem($oItem);
	return $this;
	
}
function &addButton($texthtml,$args){
	$oItem = new NObject;
	$oItem->type="button";
	
	$oItem->text=$texthtml;
	if (is_array($args)) $args=(object) $args;
	$oItem->set('class',$args->class);
	$oItem->set('href',$args->href);
	$oItem->set('onclick',$args->href);


	$this->addItem($oItem);
	return $this;
	
}
function &addSplitter($br=false){
	
	
	if ($br)
	$oItem->text='<span style=\"clear:"both;\"><br/></span>';
	else 
	$oItem->text='&nbsp;&nbsp;';
	$this->addCaption($oItem->text);
	return $this;
	
}
function &addLink($href="",$text=""){
	$oItem->type='a';
	$oItem->href=$href;
	$oItem->text=$text;
	$this->addItem($oItem);
	return $this;

	
}
}
?>